/*MyPhotoIndex Free Photo Organizer <www.myphotoindex.com>
  Copyright (C) <2006-2009>  <Asaf Yarkoni asaf@yarkoni.net>

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.*/
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using MyPhotoIndex.Plugins.ImageFormatProviders;
using MyPhotoIndex.Utilities;
using System.Collections.ObjectModel;

namespace MyPhotoIndex.Importer.CameraImageAcquisition
{
    public class RemovableDrive : ImagingDevice
    {
        internal RemovableDrive(DriveInfo driveInfo)
        {
            Name = driveInfo.Name;
            Description = string.Format("({0}) {1}", driveInfo.Name, "Camera or card reader");
        }

        public override void DownloadImages()
        {
            ImageList.Clear();

            GetImages(ImageList, Name);
        }

        internal void GetImages(List<IAcquiredImage> imageList, string root)
        {
            FilesSearch fs = new FilesSearch();
            fs.SearchLocations.Add(root);
            fs.SearchSubfolders = true;
            fs.SearchPattern = ImageFormatProviders.Default.ImporterFilterFormat;
            fs.FilesSearchEvent += new EventHandler<FileSearchEventAgs>(fs_FilesSearchEvent);
            fs.Search();
            ReadOnlyCollection<String> files = fs.FileList;
            foreach (String file in files)
            {
                RemovableDriveImage image = new RemovableDriveImage(file);
                imageList.Add(image);
                base.InvokeThumbnailDownloadEvent(new ImagingDeviceImageTransferEventArgs(files.Count, ImageList.Count, image.Name));
            }
        }

        void fs_FilesSearchEvent(object sender, FileSearchEventAgs e)
        {
            base.InvokeThumbnailDownloadEvent(new ImagingDeviceImageTransferEventArgs(0, 0, e.DirectoryName));

        }
    }
}
